package com.fowo.api.service.handleWork.supplier;

import com.fowo.api.model.development.task.DevelopmentTaskSubmitToAction;
import com.fowo.api.model.development.task.DevelopmentTaskVo;
import com.fowo.api.service.DevelopmentTaskService;
import com.fowo.api.service.impl.DevelopmentTaskServiceImpl;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

@Component
public class developmentTaskSubmitToAction implements DevelopmentTaskSubmitToAction {
    @Resource
    private DevelopmentTaskServiceImpl developmentTaskService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public synchronized void run(List<Long> idList) throws Exception {
            for(int i=0;i<idList.size();i++){
                DevelopmentTaskVo voById = developmentTaskService.getVoById(idList.get(i));
                Assert.isTrue(voById.getState().equals("0"),"违规操作");
                voById.setState("1");
                developmentTaskService.update(voById);
            }
    }
}
